package base;
class Variable{
	int i;
	/**
	 * @return the i
	 */
	public int getI() {
		return i;
	}

	/**
	 * @param i the i to set
	 */
	public void setI(int i) {
		this.i = i;
	}

	public Variable(int i){
		this.i = i;
	}
	
	public void increment(){
		synchronized (this) {
			i++;
		}
	}
	
}
class TestThread implements Runnable{
 
	private Variable var;
	public TestThread(Variable var){
		this.var = var;
		
	}
	public void run() {
		System.out.println(var.getI());
	}
	
}

public class Run10Threads {

	
	public static void main(String[] args) throws InterruptedException {
		Variable var = new Variable(1);
       Thread[] threads = new Thread[10];
       
       for(int i=0;i<10;i++){
    	   threads[i] = new Thread(new TestThread(var));
    	   threads[i].start();
    	   threads[i].join();
    	   var.increment();
       }
	}

}
